<%@ page language="java" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>
	<%@include file="../common/base.jsp"%>
	<meta charset="utf-8" />
	<meta name ="viewport" content ="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
	<meta http-equiv="expires" content="0">
	<title>待上车</title>
    <link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${base}/css/global.css?version=${version}">
    <link rel="stylesheet" type="text/css" href="${base}/css/takecar.css?version=${version}">
	<style>
		body{
			position: absolute;
			left: 0;
			right: 0;
			top: 0;
			bottom: 0;
			min-height: 510px;
		}
		.l-footer{
			position: absolute;

		}
	</style>
</head>
<body>
    <div class="container-fluid">
    	<div class="divBox driver-info">
			<%@include file="driverHtml.jsp"%>
			<p class="tip">
				司机已到达，请尽快上车
			</p>
    	</div>
		<%@include file="startEnd.jsp"%>
    	 <div class="divBox costBox row">
    		<div class="col-xs-4">
    			<span style="font-size: 26px;" id="waitFare">0</span>元
    		</div>
    		<div class="col-xs-8">
    			<span style="color:#999;">已等待</span>
    			<span style="color: #3e88f5;" id="waitTime"></span>
    		</div>
    	</div>
    </div>
	<div class="l-footer">
		<div class="cancelBox" >
			<img src="${base}/images/cancel.png">
			<p class="text">取消订单</p>
		</div>
		<%@include file="footer.jsp"%>
	</div>
</body>
<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/js/localStorageOpt.js?version=${version}"></script>
<script type="text/javascript" src="${base}/plugin/layer-v3.0.3/layer.js"></script>
<%--<script type="text/javascript" src="${base}/plugin/crypto-js/crypto-js.min.js"></script>--%>
<%--<script type="text/javascript" src="${base}/plugin/jsencrypt/jsencrypt.min.js"></script>--%>
<script type="text/javascript" src="${base}/js/utils.js?version=${version}"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
    var $document = $(document);
    var yun=new yueajax( "${openId}");
	//取消订单
    $document.on('touchend', '.cancelBox', function(event){
        var url='${base}/api/v1/passenger/token/order/cancelDescription';
		yun.ajax_md5(
		    {
            	orderUuid:yun.orderUuid
			},
            url,
			function (data) {
		        var d=data.data;
		        var total=d.totalFare || 0;
		        if(!total){//无取消费用
					changeUrl('cancelConfirmNoPay',yun.orderUuid)
				}else{//有取消费用
                    changeUrl('cancelConfirmYesPay',yun.orderUuid+'&cancelTotal='+total+'&details='+d.details)
				}
            },
			function (data) {
				layer.msg(data.msg);
            }
		)
	});
    //初始化请求订单数据
    getOrderStatus(function (data) {
        //订单创建时间
        var cTime=new Date(data.data.createOn);
        var cTobj=yun.time_count(cTime)
        var driver=data.data.driver;
        $('#faceimg').attr('src',driver.face || '${base}/images/man.png');
        $('#driver_name').html(driver.name);
        $('#driver_score').append(driver.score)
        $('#driver_orderCount').html(driver.orderCount+'单')
        $('#driver_plateNum').html(driver.plateNum)
        $('#driver_carColor_brandName').html(driver.carColor+driver.brandName);
        $('#driver_mobile').attr('href','tel:'+driver.mobile);
        $('#clickCall').attr('href','tel:'+driver.mobile);

        $('#creadtime').html(cTobj.day+'  '+cTobj.hour+cTime.format('hh:mm'));
        $("#originDetailAddressText").html(data.data.originAddress);
        $("#destDetailAddressText").html(data.data.destAddress);
    });
	//定时请求OrderDetail，获取订单详情
	var interval = setInterval(getOrderStatus,5000);
	//获取刚才派出的订单ID
	function getOrderStatus(callback) {
        yun.order_ajax(function(data){
            var d=data.data;
            if (d.subStatus != 220) {
                changeUrl(data.data.subStatus,yun.orderUuid);
            }
            if(typeof callback =="function"){
                callback(data);
            }
            //请求司机出发后的实时计算路程、时间、预算费用。
			yun.waitFare_ajax(function (data) {
				$('#waitFare').html(data.data.waitFare);
				if(!$('#waitTime').data('waitTime')){
                    $('#waitTime').data('waitTime',data.data.waitTime);
                    computingTime();
				}
            },function (data) {
			    clearInterval(interval);
				layer.msg(data.msg)
			})
        },function (data) {
//            layer.msg(data.msg());clearInterval(interval);
        })

//		$.ajax({
//			type: "POST",
//			url: "/wx/Order/info",
//			dataType: "json",
//			data: {orderUuid: orderUuid},
//			success: function (data) {
//				if (data.success) {
//					if(data.data.subStatus!=220){
//						changeUrl(data.data.subStatus);
//						if (data.data.subStatus == 91220) {
//						    //司机取消订单，跳转到cancelNoPay
//						    window.location.href = "/yue/cancelNoPay";
//						}
//					}
//				}
//			}
//		});
	}
//等待时间本地计算时间
	function computingTime(){
	    var wt=(+$('#waitTime').data('waitTime')|| 0);
	    var t=parseInt(wt)
		var m=parseInt(t/60);
	    	m=(m<10?"0"+m:m);
		var s=parseInt(t%60);
        	s=(s<10?"0"+s:s);
        $('#waitTime').html(m +":"+s);
        $('#waitTime').data('waitTime',t+1);
	    setTimeout(computingTime,1000)
    }
});
</script>
</html>